﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PatternObserver
{
    class Program
    {
        static void Main(string[] args)
        {

            ZhangSan zhangSan = new ZhangSan();
            zhangSan.Borrow(new WangWu());
            zhangSan.Borrow(new Lisi());
            
            zhangSan.Notify();

            Console.ReadKey();
        }
    }

    //
    interface IDebit
    {
        void Borrow(ICredit credit );
        void Notify();

    }
     
    class ZhangSan : IDebit
    {
        List<ICredit> credits = new List<ICredit>();
        public void Borrow(ICredit credit)
        {
            credits.Add(credit); 
        }

        public void Notify()
        {
            credits.ForEach(c => c.TakeMoney());      
        }
    }
     
    interface ICredit
    { 
        void TakeMoney(); 
    }

    class WangWu : ICredit
    {
        public void TakeMoney()
        {
            Console.WriteLine("WangWu TAKEMONEY"); ;
        }
    }
     
    class Lisi : ICredit
    {
        public void TakeMoney()
        {
            Console.WriteLine("Lisi TAKEMONEY"); ;
        }
    }


}
